<template>
    <div class="business_option">
        <div class="business_content">
            <Form ref="businessTypeForm" :model="businessTypeForm" :rules="businessTypeFormValidate"
                  :label-width="140">
                <div>
                    <Row>
                        <Col span="8">
                            <FormItem label="申请编号">
                                <Input v-model="applyNo" :disabled="true"/>
                            </FormItem>
                        </Col>
                    </Row>
                    <Row v-if="isShowDealerId">
                        <Col span="8" v-if="isShowDealerId">
                            <FormItem label="选择车商" prop="dealerId">
                                <Select v-model="businessTypeForm.dealerId" :label-in-value="true"
                                        @on-change="selectDealer" @on-open-change="openDealer" clearable
                                        :disabled="isShowDetails||isReconsider">
                                    <Option :value="item.carDealerId" v-for="(item,index) in dealerlist" :key="index">
                                        {{item.channelFullName}}
                                    </Option>
                                </Select>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <FormItem label="销售顾问" prop="saleAdvisor">
                                <Input v-model="businessTypeForm.saleAdvisor"
                                       :disabled="isShowDetails||isReconsider"/>
                            </FormItem>
                        </Col>
                        <Col span="8">
                            <FormItem label="联系电话" prop="salePhone">
                                <Input v-model="businessTypeForm.salePhone" :disabled="isShowDetails||isReconsider"/>
                            </FormItem>
                        </Col>
                    </Row>
                </div>
                <!-- 业务类型 -->
                <div class="common_br">
                    <h2 class="common_title extra_title">
                        业务类型
                        <span v-show="!isShowDetails" @click="saveOrder()" class="saveBtn">保存</span>
                    </h2>
                    <div class="common_content">
                        <Row>
                            <Col span="8">
                                <FormItem label="业务类型" prop="businessType">
                                    <RadioGroup v-model="businessTypeForm.businessType" @on-change="selectRadio">
                                        <Radio label="01"
                                               :disabled="isShowDetails || isNewCarDisabled||isPreNew||isCreateNew||isReconsider">新车
                                        </Radio>
                                        <Radio label="02"
                                               :disabled="isShowDetails || isOldCarDisabled||isPreOld||isCreateOld||isReconsider">二手车
                                        </Radio>
                                    </RadioGroup>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="车辆类型" prop="carType">
                                    <Select v-model="businessTypeForm.carType" placeholder="请选择车辆类型"
                                            @on-change="selectCarType" @on-open-change='getCarType' clearable
                                            :disabled="isShowDetails||isReconsider">
                                        <Option :value="item.value" v-for="(item,index) in dataDic.carType"
                                                :key="index">{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="车辆属性" prop="carNature">
                                    <Select v-model="businessTypeForm.carNature" placeholder="请选择车辆属性"
                                            @on-change="selectCarAttr" @on-open-change='getCarAttr' clearable
                                            :disabled="isShowDetails||isReconsider">
                                        <Option :value="item.value" v-for="(item,index) in dataDic.carNature"
                                                :key="index">{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row>
                            <Col span="8">
                                <FormItem label="运营方式" prop="operateWay">
                                    <Select v-model="businessTypeForm.operateWay" placeholder="请选择运营方式"
                                            @on-open-change='getOperWay' clearable :disabled="isShowDetails||isReconsider">
                                        <Option :value="item.value" v-for="(item,index) in dataDic.operateWay"
                                                :key="index">{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="挂靠方式" prop="affiliatedWay">
                                    <Select v-model="businessTypeForm.affiliatedWay" placeholder="请选择挂靠方式"
                                            @on-change="selectAffiMode" @on-open-change='getAffiMode'
                                            clearable :disabled="isShowDetails||isReconsider">
                                        <Option :value="item.value" v-for="(item,index) in dataDic.affiliatedWay"
                                                :key="index">{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                            <Col span="8">
                                <FormItem label="购车目的" prop="carPurpose">
                                    <Select v-model="businessTypeForm.carPurpose" placeholder="请选择购目的"
                                            @on-open-change='getCarPurpose' clearable :disabled="isShowDetails||isReconsider">
                                        <Option :value="item.value" v-for="(item,index) in dataDic.carPurpose"
                                                :key="index">{{item.title}}
                                        </Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                    </div>
                </div>
            </Form>
            <!-- 挂靠信息 -->
            <Form ref="affiliatedForm"
                  :model="affiliatedForm"
                  v-if="tempAffiMode!='00' && tempAffiMode!='' && tempAffiMode!=null"
                  :rules="affiliatedFormValidate"
                  :label-width="140"
                  @submit.native.prevent
            >
                <affiliated-way
                    :isReconsider="isReconsider"
                    :affiliatedForm="affiliatedForm"
                    :tempAffiMode="tempAffiMode"
                    :applyNo="applyNo"
                    :tempaffiliatedId="tempaffiliatedId"
                    :capitalId="capitalId"
                    :tempChannelId="tempChannelId"
                    ref="affiliatedWay"
                    :location="location"
                    :businessTypeForm="businessTypeForm"
                    @saveAffiliatedId="saveAffiliatedId"
                    :tempAffiInfo="tempAffiInfo"
                    :isShowDetails="isShowDetails"
                    @queryRecordAddress="queryRecordAddress"
                    @checkAffiliateCar="valiateAffiliateCar"
                    :valiateAffiliated="valiateAffiliated"
                >
                </affiliated-way>
            </Form>
            <!-- 新车，挂牌车，二手车 -->
            <Form ref="optionForm" :model="optionForm" :rules="optionFormValidate" :label-width="140">
                <new-car
                    :optionForm="optionForm"
                    v-if="businessType=='01'&&carAttr!='02'&&tempCarType!='03'"
                    @queryVehicleData="queryVehicleData"
                    @saveCapitalInfo="saveCapitalInfo"
                    :isShowDetails="isShowDetails"
                    :isReconsider="isReconsider"
                    @loadDataAddress="loadAddress"
                    :dynamicLocation="dynamicLocation"
                    :location="location"
                    :isNetLocation="isNetLocation"
                    :diffType="diffType"
                ></new-car>
                <plate-car
                    :optionForm="optionForm"
                    v-if="businessType=='01'&&carAttr=='02'&&tempCarType!='03'"
                    @saveCapitalInfo="saveCapitalInfo"
                    :location="location"
                    :isShowDetails="isShowDetails"
                    :isReconsider="isReconsider"
                    :dynamicLocation="dynamicLocation"
                    @loadDataAddress="loadAddress"
                    :isNetLocation="isNetLocation"
                    @checkPlateCar="valiatePlateCar"
                    @resetPlateVinInfo="resetPlateVinInfo"
                    @deliverPlateData="receivePlateData"
                    :useCarNumber="useCarNumber"
                ></plate-car>
                <old-car
                    :optionForm="optionForm"
                    v-if="businessType=='02'&&tempCarType!='03'"
                    @saveCapitalInfo="saveCapitalInfo"
                    :location="location"
                    :isShowDetails="isShowDetails"
                    :isReconsider="isReconsider"
                    @checkOldCar="valiateOldCar"
                    :dynamicLocation="dynamicLocation"
                    @loadDataAddress="loadAddress"
                    @resetOldVinInfo="resetOldVinInfo"
                    :isNetLocation="isNetLocation"
                ></old-car>
            </Form>
        </div>
        <div v-if="false">
            <Button type="primary" @click="handleSubmit('optionForm')">Submit</Button>
        </div>
        <!--品牌车型弹窗-->
        <div v-if="isShowModel">
            <char-cascade
                @close-model="closeModel"
                @carinfo="carinfo"
                :modelLibType="modelLibType"
                :businessType="businessType"
                :carType="businessTypeForm.carType"
            ></char-cascade>
        </div>
    </div>
</template>
<script>
    import NewCar from "./new-car/newCar.vue"
    import PlateCar from "./plate-car/plateCar.vue"
    import OldCar from "./old-car/oldCar.vue"
    import AffiliatedWay from "./affiliated-way/affiliatedWay.vue"
    import * as utils from '_p/afs-apply/assets/js/utils.js'
    import CharCascade from "@/components/char-cascade"
    import {formatDate} from "@/components/iview/components/date-picker/util";

    import {
        getBusinessType,
        getCarDealList,
        getOrderInfo,
        getCarInfo,
        getAffiliatedInfo,
        saveOrderInfo,
        updateOrderInfo,
        saveCarInfo,
        updateCarInfo,
        saveBusinessOption,
        noDealerGetAddressList
    } from '_p/afs-apply/api/apply-report/personal/businessOption.js'
    import {
        getDictDataByType,
        getByTypes
    } from "_p/basic/api/admin/datadic.js";
    import {getLocation} from "_p/afs-apply/api/apply-report/personal/common.js"
    import {carType, carNature, operateWay, affiliatedWay, carPurpose} from '_p/afs-apply/assets/js/staticData.js'
    import validator from '_c/rui-auto/validate/rules'
    import {deepClone} from "@/libs/utils/ObjectClone";

    import {getUserInfo} from '@/projects/basic/api/admin/user'

    export default {
        name: "business_option",
        data() {
            let validateInteger = (rule, value, callback) => {
                if (value) {
                    if (!utils.isPositiveInteger(value)) {
                        callback(new Error("格式为正整数"))
                        return;
                    }
                }
                callback()
            }
            let isSalePriceValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isTwoDicmal(value)) {
                        callback(new Error("最多为两位小数"))
                        return;
                    } else {
                        // 新车
                        // if(this.businessType=='01'&&this.carAttr!='02'){
                        if (this.businessType == '01') {
                            // 销售价格小于等于指导价格
                            if (parseFloat(value) > parseFloat(this.optionForm.guidePrice)) {
                                callback(new Error("小于等于指导价"))
                                return;
                            }
                        }
                    }
                }
                callback()
            }
            let isEvaluatePriceValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isTwoDicmal(value)) {
                        callback(new Error("最多为两位小数"))
                        return;
                    } else {
                        // 二手车
                        if (this.businessType == '02') {
                            // 评估价格小于新车购车价格
                            if (parseFloat(value) >= parseFloat(this.optionForm.guidePrice)) {
                                callback(new Error("应小于新车购车价格"))
                            }
                        }
                    }
                }
                callback()
            }
            let isUsedCarSalePriceValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isTwoDicmal(value)) {
                        callback(new Error("最多为两位小数"))
                        return;
                    } else {
                        // 二手车
                        if (this.businessType == '02') {
                            // 二手车销售价格小于新车购车价格
                            if (parseFloat(value) > parseFloat(this.optionForm.guidePrice)) {
                                callback(new Error("应小于等于新车购车价格"))
                            }
                            // 二手车销售价格小于等于评估价格
                            // if (parseFloat(value) > parseFloat(this.optionForm.evaluatingPrice)) {
                            //     callback(new Error("应小于等于评估价格"))
                            //     return;
                            // }
                        }
                    }
                }
                callback()
            }
            let isVinNoValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isCharNum(value)) {
                        callback(new Error("格式为英文与数字"))
                        return;
                    } else {
                        if (value.length != 17) {
                            callback(new Error("vin号位数为17位"))
                            return;
                        }
                    }
                }
                callback()
            }
            let plateNoValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isPlateNo(value)) {
                        callback(new Error("至少7位字母,中文,数字"))
                        return;
                    } else {
                        let firstchar = value.substr(0, 1);
                        let secondechar = value.substr(1, 1);
                        if (!/[\u4e00-\u9fa5]/.test(firstchar) || !/[A-Za-z]/.test(secondechar)) {
                            callback(new Error("车牌号首位为中文,第二位为英文"))
                            return;
                        }
                    }
                }
                callback()
            }
            let mileageValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isTwoDicmal(value)) {
                        callback(new Error("最多为两位小数"))
                        return;
                    } else {
                        // 二手车
                        if (this.businessType == "02") {
                            if (parseFloat(value) > 200000) {
                                callback(new Error("小于等于200000公里"))
                                return;
                            }
                        }
                        // 挂牌新车
                        if (this.businessType == '01' && this.carAttr == '02') {
                            if (parseFloat(value) > 100) {
                                callback(new Error("小于等于100公里"))
                                return;
                            }
                        }
                    }
                }
                callback()
            }
            let belCertNoValiate = (rule, value, callback) => {
                if (value) {
                    if (!utils.isLetterNum(value)) {
                        callback(new Error("格式为数字,字母,数字与字母"))
                        return;
                    }
                }
                callback();
            }
            let affiliatedNameValiate = (rule, value, callback) => {
                if (value) {
                    if (value.indexOf('有限公司') != "-1" || value.indexOf('有限责任公司') != "-1" || value.indexOf('股份有限公司') != "-1") {
                        callback(new Error("不允许出现有限公司、有限责任公司和股份有限公司文字"))
                        return;
                    }
                }
                callback();
            }
            return {
                modelLibType: "afsApply",
                useCarNumber: "0",//没上牌
                channelInfo: {},
                // 挂牌车对象数据
                plateData: {},
                // 判断车商是否存在
                isShowDealerId: false,
                isNetLocation: false,
                plateNoValiate: plateNoValiate,
                dynamicLocation: [],
                username: '',
                applyNo: "",
                orderId: "",
                capitalId: "",
                tempaffiliatedId: "",
                isShowModel: false,
                isdisabled: true,
                businessType: "01",//业务类型
                carAttr: "",//车辆属性新车
                tempCarType: "",//车辆类型
                tempAffiMode: "00",
                location: [],
                // 车商id
                tempChannelId: "",
                // 挂靠信息
                tempAffiInfo: {},
                // 车商列表
                dealerlist: [],
                // 初始化数据字典
                dataDic: {
                    carType: [],
                    carNature: [],
                    operateWay: [],
                    affiliatedWay: [],
                    carPurpose: [],
                },
                businessTypeForm: {
                    dealerId: "",
                    dealerName: "",//车商名称
                    saleAdvisor: "",//销售顾问
                    salePhone: "",//电话
                    // 业务类型
                    businessType: "01",
                    carType: "",
                    carNature: "",
                    operateWay: "",
                    affiliatedWay: "",
                    carPurpose: "",
                },
                brandId: "",//品牌id
                modelId: "",//车型id
                styleId: "",//款式id


                purchaseProvince: "",//购车省id,
                purchaseCity: "",//购车市id,
                licenseProvince: "",//上牌省id,
                licenseCity: "",//上牌市id

                registOptionProvince: "",//注册省id
                registOptionCity: "",//注册市id
                dealerProvince: "",//车商省id
                dealerCity: "",  //车商市id

                optionForm: {
                    // 新车与挂牌车与二手车资产信息的公共字段
                    brandName: "",
                    modelName: "",
                    styleName: "",
                    purchaseLocation: [],//购车地点
                    // salePrice:"",//车辆价格
                    guidePrice: "",//指导价
                    licenseLocation: [],//上牌地点

                    //新车与挂牌车资产信息的公共字段
                    salePrice: "",//车辆价格

                    // 挂牌汽车与二手车资产信息的公共字段
                    carVin: "",
                    engineNo: "",
                    carFunction: "",
                    mileage: "",
                    carBelongs: "",
                    belongsCertNo: "",
                    transNums: 0,

                    // 挂牌车车辆手续信息字段
                    vehicleMadeDate: "",
                    firstLandingDate: "",
                    licensePlate: "",
                    firstLicenseAddress: [],
                    evaluationPrice: "",

                    // 二手车资产信息字段
                    carBodyClass: "",
                    carColor: "",
                    fuelType: "",
                    carDisplacement: "",//排量
                    carTransmission: "",//变速器
                    totalPassenger: 0,//核定载客
                    fullModelNum: "",//车辆型号
                    secondSalePrice: "",
                    evaluatingPrice: "",
                    belongsAddress: "",

                    // 二手车车辆手续信息字段
                    carAppraiser: "",//评估师
                    dealerName: "",
                    dealerPhone: "",
                    dealerLocation: [],
                    dealerAddress: "",
                    // dealerDetail:"",
                    yearTransNum: 0,//一年内过户次数
                    isCirTrans: "",
                    isMortgage: "",
                    registLocation: [],//注册地点

                },
                registAffiliatedProvince: "",//注册省id
                registAffiliatedCity: "",//注册市id
                // 挂靠信息表单
                affiliatedForm: {
                    // 挂靠信息
                    // 第三方公司挂靠与个体工商户与网约车公用字段
                    affiliatedId: "",
                    affiliatedName: "",//公司名称

                    socUniCrtCode: "",//统一社会信用代码
                    legalName: "",//法人姓名
                    legalPhone: "",//联系电话
                    licenceEndDate: "",//运输许可证有效期
                    registLocation: [],//注册公司地址
                    registAddress: "",
                    // 网约车挂靠
                    platformId: "",
                    cooperPlatform: "",
                },
                businessTypeFormValidate: {
                    dealerId: [
                        {required: true, message: "车商不能为空", trigger: "change"}
                    ],
                    salePhone: [
                        {validator: utils.isMorePhoneValiate, trigger: "blur"}
                    ],
                    // 业务类型校验
                    businessType: [
                        {required: true, message: "请选择业务类型", trigger: "change"}
                    ],
                    carType: [
                        {required: true, message: "车辆类型不能为空", trigger: "change"}
                    ],
                    carNature: [
                        {required: true, message: "车辆属性不能为空", trigger: "change"}
                    ],
                    operateWay: [
                        {required: true, message: "运营方式不能为空", trigger: "change"}
                    ],
                    affiliatedWay: [
                        {required: true, message: "挂靠方式不能为空", trigger: "change"}
                    ],
                    carPurpose: [
                        {required: true, message: "购车目的不能为空", trigger: "change"}
                    ],
                },
                optionFormValidate: {
                    // 新车资产信息校验
                    brandName: [
                        {required: true, message: "品牌不能为空", trigger: "blur"}
                    ],
                    modelName: [
                        {required: true, message: "车型不能为空", trigger: "blur"}
                    ],
                    styleName: [
                        {required: true, message: "款式不能为空", trigger: "blur"}
                    ],
                    guidePrice: [
                        {required: true, message: "指导价不能为空", trigger: "blur"},
                        {validator: utils.isTwoDicmalValiate, trigger: "blur"}
                    ],
                    salePrice: [
                        {required: true, message: "车辆价格不能为空", trigger: "blur"},
                        {validator: isSalePriceValiate, trigger: "blur"}
                    ],
                    licenseLocation: [
                        {required: true, message: "上牌地点不能为空", trigger: "change", type: "array"}
                    ],
                    purchaseLocation: [
                        {required: true, message: "购车地点不能为空", trigger: "change", type: "array"}
                    ],
                    // 挂牌车资产信息校验
                    carVin: [
                        {required: true, message: "VIN号不能为空", trigger: "blur"},
                        {validator: isVinNoValiate, trigger: "blur"}
                    ],
                    carFunction: [
                        {required: true, message: "使用性质不能为空", trigger: "change"}
                    ],
                    engineNo: [
                        {required: true, message: "发动机号不能为空", trigger: "blur"},
                        {validator: utils.isMoreCharNumValitate, trigger: "blur"}
                    ],
                    // 挂牌车车辆信息校验
                    mileage: [
                        {required: true, message: "表显里程不能为空", trigger: "blur"},
                        {validator: mileageValiate, trigger: "blur"}
                    ],
                    vehicleMadeDate: [
                        {required: true, message: "车辆出厂日期不能为空", trigger: "change", type: 'date'}
                    ],
                    carBelongs: [
                        {required: true, message: "所有人不能为空", trigger: "blur"}
                    ],
                    belongsCertNo: [
                        {required: true, message: "所有人证件号不能为空", trigger: "blur"},
                        {validator: belCertNoValiate, trigger: "blur"}
                    ],

                    // 二手车资产信息校验
                    carBodyClass: [
                        {required: true, message: "车身级别不能为空", trigger: "blur"}
                    ],
                    carColor: [
                        {required: true, message: "车辆颜色不能为空", trigger: "blur"}
                    ],
                    fuelType: [
                        {required: true, message: "燃油种类不能为空", trigger: "change"}
                    ],
                    carDisplacement: [
                        {required: true, message: "排量不能为空", trigger: "blur"}
                    ],
                    carTransmission: [
                        {required: true, message: "变速器不能为空", trigger: "change"}
                    ],
                    totalPassenger: [
                        {required: true, message: "核定载客不能为空", trigger: "blur", type: "number"}
                    ],
                    fullModelNum: [
                        {required: true, message: "车辆型号不能为空", trigger: "blur"},
                        {validator: utils.isCharNumValitate, trigger: "blur"}
                    ],
                    secondSalePrice: [
                        {required: true, message: "二手车销售价格不能为空", trigger: "blur"},
                        {validator: isUsedCarSalePriceValiate, trigger: "blur"}

                    ],
                    evaluatingPrice: [
                        // {required: true, message: "评估价格不能为空", trigger: "blur"},
                        // {validator: isEvaluatePriceValiate, trigger: "blur"}
                    ],
                    // licensePlate: [
                    //     {required: true, message: "车牌号不能为空", trigger: "blur"},
                    //     {validator: plateNoValiate, trigger: "blur"}
                    // ],
                    dealerName: [
                        {required: true, message: "车商姓名不能为空", trigger: "blur"}
                    ],
                    dealerPhone: [
                        {required: true, message: "车商联系电话不能为空", trigger: "blur"},
                        {validator: utils.isMorePhoneValiate, trigger: "blur"}
                    ],
                    dealerLocation: [
                        {required: true, message: "车商联系地址不能为空", trigger: "change", type: "array"}
                    ],
                    dealerAddress: [
                        {required: true, message: "详细地址不能为空", trigger: "blur"}
                    ],
                    yearTransNum: [
                        {required: true, message: "一年内过户次数不能为空", trigger: "blur", type: "number"},
                    ],
                    isCirTrans: [
                        {required: true, message: "循环过户不能为空", trigger: "change"}
                    ],
                    isMortgage: [
                        {required: true, message: "抵押不能为空", trigger: "change"}
                    ],
                    registLocation: [
                        {required: true, message: "注册地址不能为空", trigger: "change", type: "array"}
                    ],
                },
                affiliatedFormValidate: {
                    // 挂靠信息
                    socUniCrtCode: [
                        {required: true, message: "统一信用社会代号不能为空", trigger: "blur"}
                    ],
                    legalName: [
                        {required: true, message: "法人姓名不能为空", trigger: "blur"}
                    ],
                    legalPhone: [
                        {required: true, message: "联系电话不能为空", trigger: "blur"}
                    ],
                    platformId: [
                        {required: true, message: "网约车平台不能为空", trigger: "change"}
                    ],
                    cooperPlatform: [
                        {required: true, message: "网约车平台不能为空", trigger: "change"}
                    ],
                    affiliatedName: [
                        {required: true, message: "个体工商挂靠名称不能为空", trigger: "blur"},
                        {validator: affiliatedNameValiate, trigger: "blur"}
                    ],
                    affiliatedId: [
                        {required: true, message: "公司名称/运营公司不能为空", trigger: "change"}
                    ],
                    registLocation: [
                        {required: true, message: "注册地址不能为空", trigger: "change", type: "array"}
                    ],
                    registAddress: [
                        {required: true, message: "详细地址不能为空", trigger: "blur"}
                    ]
                },
                isNewCarDisabled: true,
                isOldCarDisabled: true,
                isPreNew: false,
                isPreOld: false,
                isCreateNew: false,
                isCreateOld: false,
            }
        },
        //  inject: ['curTab'],
        components: {
            NewCar,
            PlateCar,
            OldCar,
            AffiliatedWay,
            CharCascade,
        },
        props: {
            preId: {
                type: String,
            },
            curTab: {
                type: Number,
            },
            isShowDetails: {
                type: Boolean,
            },
            isReconsider: {
                type: Boolean,
            },
            remarkForm: {
                type: Object,
            },
            diffType:{
                type:String
            }
        },
        created() {
            console.log("预审批id:", this.preId)
            if (this.curTab == "0") {
                this.getComonLocation();
                // 申请编号存在调接口
                let applyData = this.afs.getPageParams(this);
                let prebusiType = "";
                let prediffType = "";
                if (applyData && applyData.data) {
                    prebusiType = applyData.data.businessType;
                    prediffType = applyData.diffType;
                }
                this.setCurrentUserBusinessType(prediffType, prebusiType);
                console.log("是否进入此函数----", applyData)
                if (applyData) {
                    if (Object.keys(applyData).length > 0) {
                        this.applyNo = applyData.applyNo;
                        if (this.applyNo) {
                            this.initDatadic();
                            // 调用订单信息，挂靠信息，资产信息接口
                            this.finalQueryInfo()
                        }
                    }
                }
            }
        },
        watch: {
            curTab(val) {
                if (val == "0") {
                    // 申请编号存在调接口
                    if (this.applyNo) {
                        // 调用订单信息，挂靠信息，资产信息接口
                        this.finalQueryInfo()
                    }
                }
            },
        },
        mounted() {
        },
        methods: {
            deliverBusinessType() {
                return this.businessTypeForm.businessType;
            },
            validateAll(callback) {
                let self = this;
                Promise.all([Promise.resolve(self.$refs.businessTypeForm.validate()), Promise.resolve(self.$refs.optionForm.validate()), Promise.resolve(self.$refs.affiliatedForm ? self.$refs.affiliatedForm.validate() : true)])
                    .then((validaes) => {
                        console.log(validaes, "validaes")
                        callback(validaes.filter(item => {
                            return !item
                        }).length == 0);
                    })
            },
            finallySubmitData(btnType) {
                // 三个表单全部校验完
                this.validateAll((pass) => {
                    if (!pass) {
                        this.$Message.warning("数据录入不正确")
                        if (btnType == "nextBtn") {
                            this.$emit("valiateSelectRes", false)
                        }
                        return false;
                    }
                    let param = {};
                    param.orderInfo = {...this.businessTypeForm};
                    param.orderInfo.preId = this.preId;
                    if (this.orderId) {
                        param.orderInfo.id = this.orderId;
                        param.orderInfo.remarks = this.remarkForm.remark
                    }
                    // 三种车共同入参
                    param.carInfo = {
                        brandName: this.optionForm.brandName,
                        modelName: this.optionForm.modelName,
                        styleName: this.optionForm.styleName,
                        guidePrice: this.optionForm.guidePrice,
                        purchaseProvince: this.optionForm.purchaseLocation[0],
                        purchaseCity: this.optionForm.purchaseLocation[1],
                        licenseProvince: this.optionForm.licenseLocation[0],
                        licenseCity: this.optionForm.licenseLocation[1],
                        carNature: this.carAttr
                    }
                    // 新车与挂牌车公共字段
                    if (this.businessType == '01') {
                        param.carInfo.salePrice = this.optionForm.salePrice;
                    }
                    // 二手车与挂牌车公共字段
                    if ((this.businessType == '01' && this.carAttr == '02') || this.businessType == "02") {
                        param.carInfo.carVin = this.optionForm.carVin;
                        param.carInfo.engineNo = this.optionForm.engineNo;
                        param.carInfo.carFunction = this.optionForm.carFunction;
                        param.carInfo.mileage = this.optionForm.mileage;
                        param.carInfo.carBelongs = this.optionForm.carBelongs;
                        param.carInfo.belongsCertNo = this.optionForm.belongsCertNo;
                        param.carInfo.transNums = this.optionForm.transNums;
                    }
                    // 新车单独字段
                    if (this.businessType == '01' && this.carAttr != '02') {
                        param.carInfo.brandId = this.brandId;
                        param.carInfo.modelId = this.modelId;
                        param.carInfo.styleId = this.styleId;
                    }
                    // 挂牌车单独字段
                    if (this.businessType == '01' && this.carAttr == '02') {
                        param.carInfo.brandId = this.plateData.brandId || "";
                        param.carInfo.modelId = this.plateData.modelId || '';
                        param.carInfo.styleId = this.plateData.styleId || '';
                        let invoiceTime = this.plateData.invoiceTime.substring(0, 10)
                        param.carInfo.invoiceTime = invoiceTime || '';
                        param.carInfo.isFirstLicense = this.plateData.useCarNumber;
                        let vehicleMadeDate = formatDate(this.optionForm.vehicleMadeDate, "yyyy-MM-dd")
                        param.carInfo.vehicleMadeDate = vehicleMadeDate;
                        param.carInfo.firstLandingDate = this.optionForm.firstLandingDate;
                        param.carInfo.licensePlate = this.optionForm.licensePlate;
                        // param.carInfo.firstLicenseAddress = this.optionForm.firstLicenseAddress;
                        param.carInfo.firstLicenseProvince = this.optionForm.firstLicenseAddress[0],
                            param.carInfo.firstLicenseCity = this.optionForm.firstLicenseAddress[1],
                            param.carInfo.evaluatingPrice = this.optionForm.evaluationPrice;
                    }
                    // 二手车单独字段
                    if (this.businessType == "02") {
                        // 资产信息字段
                        param.carInfo.carBodyClass = this.optionForm.carBodyClass;
                        param.carInfo.carColor = this.optionForm.carColor;
                        param.carInfo.fuelType = this.optionForm.fuelType;
                        param.carInfo.carDisplacement = this.optionForm.carDisplacement;
                        param.carInfo.carTransmission = this.optionForm.carTransmission;
                        param.carInfo.totalPassenger = this.optionForm.totalPassenger;
                        param.carInfo.fullModelNum = this.optionForm.fullModelNum;
                        param.carInfo.secondSalePrice = this.optionForm.secondSalePrice;
                        param.carInfo.evaluatingPrice = this.optionForm.evaluatingPrice;
                        param.carInfo.belongsAddress = this.optionForm.belongsAddress

                        //车辆手续信息字段
                        param.carInfo.licensePlate = this.optionForm.licensePlate;
                        param.carInfo.carAppraiser = this.optionForm.carAppraiser;
                        param.carInfo.dealerName = this.optionForm.dealerName;
                        param.carInfo.dealerPhone = this.optionForm.dealerPhone;
                        param.carInfo.dealerProvince = this.optionForm.dealerLocation[0];
                        param.carInfo.dealerCity = this.optionForm.dealerLocation[1];
                        param.carInfo.dealerAddress = this.optionForm.dealerAddress;

                        let firstLandingDate = formatDate(this.optionForm.firstLandingDate, "yyyy-MM-dd");
                        param.carInfo.firstLandingDate = firstLandingDate;

                        param.carInfo.yearTransNum = this.optionForm.yearTransNum;
                        param.carInfo.isCirTrans = this.optionForm.isCirTrans;
                        param.carInfo.isMortgage = this.optionForm.isMortgage;
                        param.carInfo.registProvince = this.optionForm.registLocation[0];
                        param.carInfo.registCity = this.optionForm.registLocation[1];
                    }
                    if (this.capitalId) {
                        param.carInfo.id = this.capitalId;
                    }
                    // 当存在挂靠方式的时候
                    if (this.tempAffiMode != "00") {
                        param.affiliatedInfo = this.$refs.affiliatedWay.passAffiData();
                    }
                    if (this.tempaffiliatedId) {
                        param.affiliatedInfo.id = this.tempaffiliatedId;
                    }
                    // 保存的编号
                    if (this.applyNo) {
                        param.applyNo = this.applyNo;
                    }
                    this.$emit('isLoading', true);
                    saveBusinessOption(param).then(res => {
                        this.$emit('isLoading', false);
                        if (res.code == "0000") {
                            if (btnType == "nextBtn") {
                                this.$emit("valiateSelectRes", true)
                            }
                            if (btnType == "cutTable") {
                                this.$emit("optionCallSuccess", true)
                            }
                            if (!this.applyNo) {
                                this.applyNo = res.data.applyNo;
                                if (res.data.orderInfo) {
                                    this.orderId = res.data.orderInfo.id;//订单id
                                }
                                if (res.data.carInfo) {
                                    this.capitalId = res.data.carInfo.id;//车辆id
                                }
                                if (res.data.affiliatedInfo) {
                                    this.tempaffiliatedId = res.data.affiliatedInfo.id//挂靠id
                                }
                                this.$Message.success("保存业务选择成功");
                                this.$emit("deliverApplayNo", this.applyNo)
                            } else {
                                this.$Message.success("更新业务选择成功");
                            }
                        }
                    }).catch(error => {
                        this.$emit('isLoading', false);
                    })
                })
            },
            receivePlateData(obj) {
                this.plateData = obj;
                this.useCarNumber = obj.useCarNumber;
            },
            getComonLocation() {
                let param = ""
                param = {
                    level: '1',
                    upperCode: '1'
                };
                getLocation(param).then((res) => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.location.push(...res.data);
                    console.log(this.location, "location")
                })
            },
            // 购买地址是否有无车商均从渠道那边
            queryAdderssList(busiType) {
                let param = {
                    upperCode: "1",
                    username: this.username,
                }
                if (busiType == "01") {
                    param.businessType = "newCar"
                } else if (busiType == "02") {
                    param.businessType = "oldCar"
                }
                noDealerGetAddressList(param).then(res => {
                    if (res.code == "0000") {
                        res.data.forEach(item => {
                            // 表明是否是父节点
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        })
                    }
                    this.dynamicLocation = res.data;
                })
            },
            initDatadic() {
                //数据字典
                let arr = ["carType", "carNature", "operateWay", "affiliatedWay", "carPurpose"];
                getByTypes(arr).then(res => {
                    if (res.code === "0000") {
                        this.dataDic = deepClone(res.data);
                        console.log(this.dataDic, "this.dataDic")
                    }
                });
            },
            // 获取车商列表接口
            queryCarDealList() {
                this.dealerlist = [];
                let param = "";
                param = {
                    userId: "",
                    cardealerType: "",
                    businessType: this.businessType
                }
                getCarDealList(param).then(res => {
                    if (res.code == "0000") {
                        this.dealerlist = res.data
                    }
                })
            },
            // 查询订单信息
            queryOrderInfo() {
                let param = ""
                param = {
                    applyNo: this.applyNo,
                }
                this.$emit('isLoading', true);
                return new Promise((resolve, reject) => {
                    getOrderInfo(param).then(res => {
                        this.$emit('isLoading', false);
                        console.log("是否进入订单接口调用")
                        if (res.code == "0000") {
                            if (res.data) {
                                this.businessTypeForm.saleAdvisor = res.data.saleAdvisor || '';
                                this.businessTypeForm.salePhone = res.data.salePhone || '';
                                this.businessTypeForm.businessType = res.data.businessType || '';
                                this.businessTypeForm.carType = res.data.carType || '';
                                this.businessTypeForm.carNature = res.data.carNature || '';
                                this.businessTypeForm.operateWay = res.data.operateWay || '';
                                this.businessTypeForm.affiliatedWay = res.data.affiliatedWay || '';
                                this.businessTypeForm.carPurpose = res.data.carPurpose || '';
                                this.businessTypeForm.dealerId = res.data.dealerId || '';
                                this.businessTypeForm.dealerName = res.data.dealerName || "";
                                this.tempChannelId = res.data.dealerId || '';
                                this.remarkForm.remark = res.data.remarks || '';
                                // 构造车商列表
                                let tempChannelList = [];
                                if (res.data.dealerId && res.data.dealerName) {
                                    let obj = {
                                        carDealerId: res.data.dealerId || '',
                                        channelFullName: res.data.dealerName || '',
                                    }
                                    tempChannelList.push(obj);
                                    this.dealerlist = tempChannelList;
                                    console.log(this.businessTypeForm.dealerId, this.dealerlist, "this.dealerlist")
                                }
                                // 挂靠方式
                                this.tempAffiMode = res.data.affiliatedWay || '';
                                // 赋值订单id,在点击保存就是更新
                                this.orderId = res.data.id;
                                if (res.data.intoFirstDate) {
                                    if (this.businessType == "01") {
                                        this.isCreateOld = true;
                                    } else if (this.businessType == '02') {
                                        this.isCreateNew = true;
                                    }
                                }
                                resolve(res.data)
                            }
                        } else {
                            reject(res.message)
                        }
                    }).catch(error => {
                        this.$emit('isLoading', false);
                    })
                })
            },
            // 获取资产信息
            queryCarInfo(data) {
                this.businessType = data.businessType;
                this.carAttr = data.carNature;
                let param = "";
                param = {
                    carNature: data.carNature,
                    businessType: data.businessType,
                    applyNo: this.applyNo,
                }
                this.$emit('isLoading', true);
                getCarInfo(param).then(res => {
                    this.$emit('isLoading', false);
                    if (res.code == "0000") {
                        let self = this;
                        this.$nextTick(function () {
                            // 新车
                            if (self.businessType == '01' && self.carAttr == '01') {
                                // 新车直接给form表单赋值
                                if (res.data) {
                                    if (res.data.newCarInfo) {
                                        self.capitalId = res.data.newCarInfo.id;
                                        self.optionForm = Object.assign({}, self.optionForm, res.data.newCarInfo);
                                        // console.log(self.optionForm,"newCarInfo")
                                        self.brandId = res.data.newCarInfo.brandId;
                                        self.modelId = res.data.newCarInfo.modelId;
                                        self.styleId = res.data.newCarInfo.styleId;
                                        if (res.data.newCarInfo.guidePrice) {
                                            self.optionForm.guidePrice = res.data.newCarInfo.guidePrice.toString();
                                        }
                                        if (res.data.newCarInfo.salePrice) {
                                            self.optionForm.salePrice = res.data.newCarInfo.salePrice.toString();
                                        }
                                        // 购买地址
                                        let purchaseAdderss = [];
                                        purchaseAdderss[0] = res.data.newCarInfo.purchaseProvince || '';
                                        purchaseAdderss[1] = res.data.newCarInfo.purchaseCity || '';
                                        self.$set(self.optionForm, "purchaseLocation", purchaseAdderss)
                                        //上牌地址
                                        let licenseAdress = [];
                                        licenseAdress[0] = res.data.newCarInfo.licenseProvince || '';
                                        licenseAdress[1] = res.data.newCarInfo.licenseCity || '';
                                        self.$set(self.optionForm, "licenseLocation", licenseAdress)

                                    }
                                }
                            }
                            // 挂牌新车
                            else if (self.businessType == '01' && self.carAttr == '02') {
                                if (res.data.licenseCarInfo) {
                                    //挂牌新车直接给form表单赋值
                                    self.capitalId = res.data.licenseCarInfo.id;
                                    self.optionForm = Object.assign({}, self.optionForm, res.data.licenseCarInfo);

                                    let tempObj = {};
                                    tempObj.brandId = res.data.licenseCarInfo.brandId;
                                    tempObj.modelId = res.data.licenseCarInfo.modelId;
                                    tempObj.styleId = res.data.licenseCarInfo.styleId;
                                    tempObj.invoiceTime = res.data.licenseCarInfo.invoiceTime;
                                    tempObj.useCarNumber = res.data.licenseCarInfo.isFirstLicense;
                                    self.plateData = tempObj;
                                    self.useCarNumber = tempObj.useCarNumber;
                                    if (res.data.licenseCarInfo.guidePrice) {
                                        self.optionForm.guidePrice = res.data.licenseCarInfo.guidePrice.toString();
                                    }
                                    if (res.data.licenseCarInfo.salePrice) {
                                        self.optionForm.salePrice = res.data.licenseCarInfo.salePrice.toString();
                                    }
                                    if (res.data.licenseCarInfo.mileage) {
                                        self.optionForm.mileage = res.data.licenseCarInfo.mileage.toString();
                                    }
                                    self.optionForm.evaluationPrice = res.data.licenseCarInfo.evaluatingPrice;
                                    // 购买地址
                                    let purchaseAdderss = [];
                                    purchaseAdderss[0] = res.data.licenseCarInfo.purchaseProvince || '';
                                    purchaseAdderss[1] = res.data.licenseCarInfo.purchaseCity || '';
                                    self.$set(self.optionForm, "purchaseLocation", purchaseAdderss)
                                    //上牌地址
                                    let licenseAdress = [];
                                    licenseAdress[0] = res.data.licenseCarInfo.licenseProvince || '';
                                    licenseAdress[1] = res.data.licenseCarInfo.licenseCity || '';
                                    self.$set(self.optionForm, "licenseLocation", licenseAdress);

                                    //首次上牌地点
                                    let firstlicenseAdress = [];
                                    firstlicenseAdress[0] = res.data.licenseCarInfo.firstLicenseProvince || '';
                                    firstlicenseAdress[1] = res.data.licenseCarInfo.firstLicenseCity || '';
                                    self.$set(self.optionForm, "firstLicenseAddress", firstlicenseAdress);

                                    // 车辆出厂时间
                                    let vehicleMadeDate = new Date(res.data.licenseCarInfo.vehicleMadeDate) || '';
                                    self.$set(self.optionForm, "vehicleMadeDate", vehicleMadeDate)

                                }
                            }
                            // 二手车
                            else if (self.businessType == '02') {
                                if (res.data.oldCarInfo) {
                                    //二手车直接给form表单赋值
                                    self.capitalId = res.data.oldCarInfo.id;
                                    // self.optionForm=res.data.oldCarInfo;
                                    self.optionForm = Object.assign({}, self.optionForm, res.data.oldCarInfo);

                                    if (res.data.oldCarInfo.guidePrice) {
                                        self.optionForm.guidePrice = res.data.oldCarInfo.guidePrice.toString();
                                    }
                                    if (res.data.oldCarInfo.secondSalePrice) {
                                        self.optionForm.secondSalePrice = res.data.oldCarInfo.secondSalePrice.toString();
                                    }
                                    if (res.data.oldCarInfo.evaluatingPrice) {
                                        self.optionForm.evaluatingPrice = res.data.oldCarInfo.evaluatingPrice.toString();
                                    }
                                    if (res.data.oldCarInfo.mileage) {
                                        self.optionForm.mileage = res.data.oldCarInfo.mileage.toString();
                                    }

                                    // 购买地址
                                    let purchaseAdderss = [];
                                    purchaseAdderss[0] = res.data.oldCarInfo.purchaseProvince || '';
                                    purchaseAdderss[1] = res.data.oldCarInfo.purchaseCity || '';
                                    self.$set(self.optionForm, "purchaseLocation", purchaseAdderss)

                                    //上牌地址
                                    let licenseAdress = [];
                                    licenseAdress[0] = res.data.oldCarInfo.licenseProvince || '';
                                    licenseAdress[1] = res.data.oldCarInfo.licenseCity || '';
                                    self.$set(self.optionForm, "licenseLocation", licenseAdress)
                                    // 注册地址
                                    let registAddress = [];
                                    registAddress[0] = res.data.oldCarInfo.registProvince || '';
                                    registAddress[1] = res.data.oldCarInfo.registCity || '';
                                    self.$set(self.optionForm, "registLocation", registAddress)
                                    // 车商地址
                                    let dealerAddress = [];
                                    dealerAddress[0] = res.data.oldCarInfo.dealerProvince || '';
                                    dealerAddress[1] = res.data.oldCarInfo.dealerCity || '';
                                    self.$set(self.optionForm, "dealerLocation", dealerAddress)

                                    let firstLandingDate = new Date(res.data.oldCarInfo.firstLandingDate) || '';
                                    self.$set(self.optionForm, "firstLandingDate", firstLandingDate)


                                }
                            }
                        })

                    }
                }).catch(error => {
                    this.$emit('isLoading', false);
                })
            },
            // 获取挂靠信息
            queryAffiliatedWayInfo(data) {
                let param = "";
                param = {
                    applyNo: this.applyNo,
                    affiliatedWay: data.affiliatedWay
                }
                getAffiliatedInfo(param).then(res => {
                    if (res.code == "0000") {
                        // 公司名称挂靠
                        if (data.affiliatedWay == "01") {
                            if (res.data.companyInfo) {
                                this.tempAffiInfo = res.data.companyInfo;
                                this.tempaffiliatedId = res.data.companyInfo.id;
                                // this.affiliatedForm.affiliatedId=res.data.companyInfo.affiliatedId||'';
                                this.affiliatedForm.socUniCrtCode = res.data.companyInfo.socUniCrtCode || '';
                                this.affiliatedForm.legalName = res.data.companyInfo.legalName || '';
                                this.affiliatedForm.legalPhone = res.data.companyInfo.legalPhone || '';
                                this.affiliatedForm.licenceEndDate = res.data.companyInfo.licenceEndDate || '';

                                let tempArr = [];
                                tempArr[0] = res.data.companyInfo.registProvince || '';
                                tempArr[1] = res.data.companyInfo.registCity || '';
                                this.$set(this.affiliatedForm, "registLocation", tempArr)
                                this.affiliatedForm.registAddress = res.data.companyInfo.registAddress;
                            }
                        }
                        // 个体工商户
                        else if (data.affiliatedWay == "02") {
                            if (res.data.personalInfo) {
                                this.tempaffiliatedId = res.data.personalInfo.id;
                                this.affiliatedForm.affiliatedName = res.data.personalInfo.affiliatedName || '';
                                this.tempAffiInfo = res.data.personalInfo;
                            }
                        }
                        // 网约车
                        else if (data.affiliatedWay == "03") {
                            if (res.data.networkInfo) {
                                this.tempaffiliatedId = res.data.networkInfo.id;
                                // this.affiliatedForm.affiliatedId=res.data.networkInfo.affiliatedId||'';
                                this.affiliatedForm.affiliatedName = res.data.networkInfo.affiliatedName || '';
                                this.affiliatedForm.platformId = res.data.networkInfo.platformId || '';
                                console.log(this.affiliatedForm.platformId, "this.affiliatedForm.platformId")
                                this.affiliatedForm.cooperPlatform = res.data.networkInfo.cooperPlatform || '';
                                this.tempAffiInfo = res.data.networkInfo;
                            }
                        }
                    }
                })
            },
            // 调取资产信息接口
            finalQueryInfo() {
                this.queryOrderInfo().then((data) => {
                    this.queryCarInfo(data);
                    this.queryAffiliatedWayInfo(data);
                })
            },
            // 选择业务类型
            selectRadio(value) {
                // 清空车商信息
                this.$refs["businessTypeForm"].fields.forEach(function (e) {
                    if (e.prop == 'dealerId') {
                        e.resetField()
                    }
                })
                //重置业务类型组的字段
                this.resetBusinessType();
                this.resetCarType();

                this.businessType = value;
                //当车商区域不存在,新车，二手购买地点区域不同
                //    if(!this.isShowDealerId){
                this.queryAdderssList(this.businessType);
                //    }
                this.cleAllComData();
                if (this.businessType == "01") {
                    this.cleNewPlateData();
                    if (this.channelInfo) {
                        if (this.channelInfo.channelBelong == "01") {
                            this.isShowDealerId = true;
                            return;
                        }
                    }
                    this.dynamicDealerId();
                } else {
                    this.clePlateOldData();
                    this.cleOldData();
                    if (this.channelInfo) {
                        if (this.channelInfo.channelBelong == "01") {
                            this.isShowDealerId = true;
                            return;
                        }
                    }
                    this.isShowDealerId = false;
                }
            },
            dynamicDealerId() {
                if (this.channelInfo) {
                    if (this.channelInfo.channelBelong != "01" && this.channelInfo.choiceCardealerSwitch == '1') {
                        this.isShowDealerId = true;
                    }
                }
            },
            // 选择车辆类型
            selectCarType(value) {
                // this.tempCarType=value;
                console.log(value, "value")
                this.resetBusinessType();
            },
            // 展开下拉框时调车辆类型接口
            getCarType(value) {
                if (value) {
                    let param = "";
                    param = {
                        businessType: this.businessTypeForm.businessType,
                        fieldName: "car_type"
                    }
                    console.log(this.channelInfo.channelBelong, "channelBelong")
                    if (this.channelInfo.channelBelong == "01") {
                        if (!this.tempChannelId) {
                            this.$Message.warning("请先选择车商");
                            return;
                        } else {
                            param.dealerId = this.tempChannelId;
                        }

                    }
                    getBusinessType(param).then(res => {
                        if (res.code == "0000") {
                            this.dataDic.carType = res.data;
                            console.log(this.dataDic.carType, "carType")
                        }
                    })
                }
            },
            // 选择车辆属性
            selectCarAttr(value) {
                this.carAttr = value
                // 切换清空新车,挂牌新车公共字段。
                this.cleAllComData();
                this.cleNewPlateData()
                // 挂牌车
                if (this.carAttr == '02') {
                    this.clePlateOldData();
                    this.clePlateData()
                    this.optionFormValidate.firstLandingDate = []
                    this.optionFormValidate.transNums = []
                }
            },
            // 展开下拉框时调车辆属性接口
            getCarAttr(value) {
                if (value) {
                    this.validateCarType('carAttr');
                }
            },
            // 展开下拉框时调运营方式接口
            getOperWay(value) {
                if (value) {
                    this.validateCarType('operWay');
                }
            },
            // 选择挂靠方式
            selectAffiMode(value) {
                if (value != "03") {
                    this.isNetLocation = false;
                    this.$set(this.optionForm, 'licenseLocation', [])
                }
                if (value) {
                    this.tempAffiMode = value;
                }
                let self = this;
                if (self.$refs.affiliatedForm) {
                    self.$refs["affiliatedForm"].fields.forEach(function (e) {
                        e.resetField();
                    })
                }
            },
            // 展开下拉框时调挂靠方式接口
            getAffiMode(value) {
                if (value) {
                    this.validateCarType('affiMode');
                }
            },
            // 展开下拉框时购车目的接口
            getCarPurpose(value) {
                if (value) {
                    this.validateCarType('carPurpose');
                }
            },
            // 对车辆类型字段进行校验
            validateCarType(type) {
                this.$refs['businessTypeForm'].validateField('carType', (carTypeValite) => {
                    if (!carTypeValite) {
                        this.getDiffType(type)
                    }
                });
            },
            // 车辆属性，运营方式，挂靠方式,购车目的接口
            getDiffType(type) {
                let fieldName = "";
                let param = "";
                param = {
                    businessType: this.businessTypeForm.businessType,
                    carType: this.businessTypeForm.carType,
                    carNature: this.businessTypeForm.carNature,
                    operateWay: this.businessTypeForm.operateWay,
                    affiliatedWay: this.businessTypeForm.affiliatedWay,
                    carPurpose: this.businessTypeForm.carPurpose,
                }
                if (type == "carAttr") {
                    fieldName = "car_nature"
                    param.carNature = "";
                } else if (type == "operWay") {
                    fieldName = "operate_way"
                    param.operateWay = "";
                } else if (type == "affiMode") {
                    fieldName = "affiliated_way"
                    param.affiliatedWay = "";
                } else if (type == "carPurpose") {
                    fieldName = "car_purpose";
                    param.carPurpose = "";
                }
                param.fieldName = fieldName;
                getBusinessType(param).then(res => {
                    if (res.code == "0000") {
                        if (type == "carAttr") {
                            this.dataDic.carNature = res.data;
                        } else if (type == "operWay") {
                            this.dataDic.operateWay = res.data;
                        } else if (type == "affiMode") {
                            this.dataDic.affiliatedWay = res.data;
                        } else if (type == "carPurpose") {
                            this.dataDic.carPurpose = res.data;
                        }
                    }
                })
            },
            // 选中款式的查询后获取的车辆信息
            carinfo(obj) {
                this.optionForm.brandName = obj.curBrandName;
                this.optionForm.modelName = obj.curModelName;
                this.optionForm.styleName = obj.curStyleName;
                this.optionForm.guidePrice = obj.curGuidePrice;
                this.optionForm.salePrice = obj.curGuidePrice;
                this.brandId = obj.curBrandId;
                this.modelId = obj.curModelId;
                this.styleId = obj.curStyleId;
                this.valiateNewCar();
            },
            // 车型库弹窗出现
            queryVehicleData() {
                this.isShowModel = true;
                this.$emit("open-model");
            },
            closeModel(value) {
                this.isShowModel = value;
            },
            // 选择车商获取label值
            selectDealer(val) {
                console.log(val, "val")
                if (val) {
                    this.businessTypeForm.dealerName = val.label.trim();
                    this.tempChannelId = val.value;
                    console.log(this.tempChannelId, "tempChannelId")
                    // let channelAdderss=[];
                    // this.dealerlist.forEach((item)=>{
                    //     if(item.carDealerId==val.value){
                    //         channelAdderss[0]=item.channelProvince;
                    //         channelAdderss[1]=item.channelCity;
                    //         console.log(channelAdderss,"channelAdderss")
                    //     }
                    // })
                    // this.$set(this.optionForm,"purchaseLocation",channelAdderss);
                }
            },
            // 下拉框展开调车商
            openDealer(val) {
                if (val) {
                    this.queryCarDealList();
                }
            },
            // 保存订单信息
            saveOrder() {
                let param = this.businessTypeForm;
                param.preId = this.preId;
                this.$refs.businessTypeForm.validate((valid) => {
                    if (valid) {
                        if (this.orderId) {
                            param.id = this.orderId;
                            param.applyNo = this.applyNo;
                            updateOrderInfo(param).then(res => {
                                if (res.code == "0000") {
                                    this.$Message.success("更新业务类型成功");
                                }
                            })
                        } else {
                            saveOrderInfo(param).then(res => {
                                if (res.code == "0000") {
                                    this.applyNo = res.data.applyNo;
                                    this.$emit("deliverApplayNo", this.applyNo)
                                    this.orderId = res.data.id;
                                    // sessionStorage.setItem('storeApplyNo',res.data.applyNo)
                                    this.$Message.success("保存业务类型成功");
                                }
                            })
                        }
                    }
                })
            },
            saveCapitalInfo(type) {
                console.log(type, "业务选择页面")
                if (!this.applyNo) {
                    this.$Message.warning("请先保存业务类型");
                    return;
                }
                this.$refs.optionForm.validate((valid) => {
                    if (valid) {
                        // 三种车共同入参
                        let param = {
                            applyNo: this.applyNo,
                            brandName: this.optionForm.brandName,
                            modelName: this.optionForm.modelName,
                            styleName: this.optionForm.styleName,
                            guidePrice: this.optionForm.guidePrice,
                            id: this.capitalId,
                            purchaseProvince: this.optionForm.purchaseLocation[0],
                            purchaseCity: this.optionForm.purchaseLocation[1],
                            licenseProvince: this.optionForm.licenseLocation[0],
                            licenseCity: this.optionForm.licenseLocation[1],
                            carNature: this.carAttr
                        };
                        // 新车与挂牌车公共字段
                        if (type == "newCar" || type == "plateCar") {
                            param.salePrice = this.optionForm.salePrice;
                        }
                        // 二手车与挂牌车公共字段
                        if (type == "plateCar" || type == "oldCar") {
                            param.carVin = this.optionForm.carVin;
                            param.engineNo = this.optionForm.engineNo;
                            param.carFunction = this.optionForm.carFunction;
                            param.mileage = this.optionForm.mileage;
                            param.carBelongs = this.optionForm.carBelongs;
                            param.belongsCertNo = this.optionForm.belongsCertNo;
                            param.transNums = this.optionForm.transNums;
                        }
                        // 新车新增入参字段
                        if (type == "newCar") {
                            param.brandId = this.brandId;
                            param.modelId = this.modelId;
                            param.styleId = this.styleId;
                        }
                        // 挂牌车单独字段
                        if (type == "plateCar") {
                            param.brandId = this.plateData.brandId || "";
                            param.modelId = this.plateData.modelId || '';
                            param.styleId = this.plateData.styleId || '';
                            let invoiceTime = this.plateData.invoiceTime.substring(0, 10);
                            param.invoiceTime = invoiceTime || '';
                            param.isFirstLicense = this.plateData.useCarNumber
                            let vehicleMadeDate = formatDate(this.optionForm.vehicleMadeDate, "yyyy-MM-dd")
                            param.vehicleMadeDate = vehicleMadeDate;
                            param.firstLandingDate = this.optionForm.firstLandingDate;
                            param.licensePlate = this.optionForm.licensePlate;
                            // param.firstLicenseAddress = this.optionForm.firstLicenseAddress;
                            param.firstLicenseProvince = this.optionForm.firstLicenseAddress[0];
                            param.firstLicenseCity = this.optionForm.firstLicenseAddress[1];
                            param.evaluatingPrice = this.optionForm.evaluationPrice;
                        }
                        // 二手车单独字段
                        if (type == "oldCar") {
                            // 资产信息字段
                            param.carBodyClass = this.optionForm.carBodyClass;
                            param.carColor = this.optionForm.carColor;
                            param.fuelType = this.optionForm.fuelType;
                            param.carDisplacement = this.optionForm.carDisplacement;
                            param.carTransmission = this.optionForm.carTransmission;
                            param.totalPassenger = this.optionForm.totalPassenger;
                            param.fullModelNum = this.optionForm.fullModelNum;
                            param.secondSalePrice = this.optionForm.secondSalePrice;
                            param.evaluatingPrice = this.optionForm.evaluatingPrice;
                            param.belongsAddress = this.optionForm.belongsAddress

                            //车辆手续信息字段
                            param.licensePlate = this.optionForm.licensePlate;
                            param.carAppraiser = this.optionForm.carAppraiser;
                            param.dealerName = this.optionForm.dealerName;
                            param.dealerPhone = this.optionForm.dealerPhone;
                            param.dealerProvince = this.optionForm.dealerLocation[0];
                            param.dealerCity = this.optionForm.dealerLocation[1];
                            param.dealerAddress = this.optionForm.dealerAddress;

                            let firstLandingDate = formatDate(this.optionForm.firstLandingDate, "yyyy-MM-dd");
                            param.firstLandingDate = firstLandingDate;

                            param.yearTransNum = this.optionForm.yearTransNum;
                            param.isCirTrans = this.optionForm.isCirTrans;
                            param.isMortgage = this.optionForm.isMortgage;
                            param.registProvince = this.optionForm.registLocation[0];
                            param.registCity = this.optionForm.registLocation[1];
                        }
                        this.$emit('isLoading', true);
                        if (this.capitalId) {
                            updateCarInfo(param).then(res => {
                                this.$emit('isLoading', false);
                                if (res.code == "0000") {
                                    this.$Message.success("更新资产信息成功");
                                }
                            }).catch(error => {
                                this.$emit('isLoading', false);
                            })
                        } else {
                            saveCarInfo(param).then(res => {
                                this.$emit('isLoading', false);
                                if (res.code == "0000") {
                                    this.capitalId = res.data.id;
                                    this.$Message.success("保存资产信息成功");
                                }
                            }).catch(error => {
                                this.$emit('isLoading', false);
                            })
                        }
                    }
                })

            },
            // 点击保存挂靠信息id
            saveAffiliatedId(id) {
                this.tempaffiliatedId = id;
            },
            // 重置清空新车/挂牌车/二手车的公共数据
            cleAllComData() {
                let _this = this;
                this.$nextTick(() => {
                    _this.$refs["optionForm"].fields.forEach(function (e) {
                        if (e.prop == 'brandName' || e.prop == "modelName" ||
                            e.prop == "styleName" ||
                            e.prop == "guidePrice") {
                            // e.resetField();
                            _this.optionForm[e.prop] = "";
                        } else if (e.prop == "purchaseLocation" || e.prop == "licenseLocation") {
                            // 当上牌地址是网约车备案地址且禁止时;
                            if (_this.isNetLocation) {
                                _this.optionForm['purchaseLocation'] = [];
                            } else {
                                _this.optionForm[e.prop] = [];
                            }
                        }
                    })
                })
            },
            //重置新车/挂牌车的公共字段
            cleNewPlateData() {
                let _this = this;
                this.$nextTick(() => {
                    _this.$refs["optionForm"].fields.forEach(function (e) {
                        if (e.prop == "salePrice") {
                            // e.resetField()
                            _this.optionForm[e.prop] = "";
                        }
                    })
                })
            },
            // 重置挂牌车/二手车的公共数据
            clePlateOldData() {
                let _this = this;
                this.$nextTick(() => {
                    _this.$refs["optionForm"].fields.forEach(function (e) {
                        // console.log(e, "e")
                        if (e.prop == 'carVin' || e.prop == "engineNo" || e.prop == "carFunction" || e.prop == "mileage" || e.prop == "carBelongs" || e.prop == "belongsCertNo") {
                            // e.resetField()
                            _this.optionForm[e.prop] = "";
                        } else if (e.prop == "transNums") {
                            _this.optionForm[e.prop] = 0;
                        }
                    })
                })
            },
            // 重置挂牌车单独字段
            clePlateData() {
                let _this = this;
                this.$nextTick(() => {
                    _this.$refs["optionForm"].fields.forEach(function (e) {
                        if (e.prop == 'vehicleMadeDate' || e.prop == "firstLandingDate" || e.prop == "licensePlate") {
                            // e.resetField()
                            _this.optionForm[e.prop] = "";
                        } else if (e.prop == "firstLicenseAddress") {
                            _this.optionForm[e.prop] = [];
                        }
                    })
                })
            },
            // 重置二手车单独字段
            cleOldData() {
                let _this = this;
                this.$nextTick(() => {
                    _this.$refs["optionForm"].fields.forEach(function (e) {
                        if (e.prop == 'carBodyClass' || e.prop == "carColor" || e.prop == "fuelType" || e.prop == "carDisplacement" || e.prop == "carTransmission" ||
                            e.prop == "fullModelNum" || e.prop == "secondSalePrice" || e.prop == "evaluatingPrice" || e.prop == "belongsAddress" ||
                            e.prop == "carAppraiser" || e.prop == "dealerName" || e.prop == "dealerPhone" ||
                            e.prop == "isCirTrans" || e.prop == "isMortgage") {
                            // e.resetField()
                            _this.optionForm[e.prop] = "";
                        } else if (e.prop == "registLocation" || e.prop == "dealerLocation") {
                            _this.optionForm[e.prop] = [];
                        } else if (e.prop == "yearTransNum" || e.prop == "totalPassenger") {
                            _this.optionForm[e.prop] = 0;
                        }
                    })
                })
            },
            // 重置表单业务类型除车辆类型的数据
            resetBusinessType() {
                this.$refs["businessTypeForm"].fields.forEach(function (e) {
                    if (e.prop == 'carNature' || e.prop == "operateWay" || e.prop == "affiliatedWay" || e.prop == "carPurpose") {
                        e.resetField()
                    }
                })
            },
            // 重置表单业务类型中车辆类型的数据
            resetCarType() {
                this.$refs["businessTypeForm"].fields.forEach(function (e) {
                    if (e.prop == 'carType') {
                        e.resetField()
                    }
                })
            },
            // 校验新车
            valiateNewCar() {
                let fieldArr = ['brandName', "modelName", "styleName", "guidePrice", "salePrice"];
                fieldArr.forEach((item, index) => {
                    this.$refs["optionForm"].validateField(item)
                })
            },
            // 校验二手车vin查询出来的字段(不为change方法的表单校验)
            valiateOldCar() {
                let fieldArr = ['brandName', "modelName", "styleName", "carColor", "carBodyClass", 'carDisplacement', "totalPassenger", "engineNo", "guidePrice"];
                fieldArr.forEach((item, index) => {
                    if (this.optionForm[item]) {
                        this.$refs["optionForm"].validateField(item)
                    }
                })
            },
            // 重置二手车vin查询出来的字段
            resetOldVinInfo() {
                let fieldArr = ['brandName', "modelName", "styleName", "carColor", "carBodyClass", 'carDisplacement', "totalPassenger", "engineNo", "guidePrice", 'fuelType', 'carTransmission', 'carFunction'];
                let self = this;
                this.$refs["optionForm"].fields.forEach(function (e) {
                    if (fieldArr.indexOf(e.prop) != '-1') {
                        if (self.optionForm[e.prop]) {
                            e.resetField()
                        }
                    }
                })
            },
            // 校验挂牌车vin查询出来的字段(不为change方法的表单校验)
            valiatePlateCar() {
                let fieldArr = ['brandName', 'modelName', 'styleName', 'guidePrice', 'engineNo', 'mileage',
                    "licensePlate", "carBelongs", "belongsCertNo"]
                fieldArr.forEach((item, index) => {
                    if (this.optionForm[item]) {
                        this.$refs["optionForm"].validateField(item)
                    }
                })
            },
            // 校验客户信息
            valiateAffiliateCar(filed) {
                filed.forEach((item, index) => {
                    if (this.affiliatedForm[item]) {
                        this.$refs["affiliatedForm"].validateField(item)
                    }
                })
            },
            // 重置挂牌车所有资产信息字段
            resetPlateVinInfo() {
                this.plateData = {};
                let fieldArr = ['brandName', "modelName", "styleName", "guidePrice", "engineNo",
                    'mileage', "vehicleMadeDate", "licensePlate", "carBelongs", 'belongsCertNo',
                    'firstLandingDate', 'carFunction', "salePrice", "licenseLocation", "purchaseLocation",
                ];
                let self = this;
                this.$refs["optionForm"].fields.forEach(function (e) {
                    if (fieldArr.indexOf(e.prop) != '-1') {
                        if (self.optionForm[e.prop]) {
                            e.resetField()
                        }
                    }
                })
            },
            // 通过角色设置新车、二手车权限
            setCurrentUserBusinessType(diffType, prebusiType) {
                var role = new Set();
                // var hasRoleCode = false;
                var roleCodeArr = new Set(['ROLE_RECORDED', 'ROLE_APPLY', 'ROLE_XCRECORDED', 'ROLE_XCAPPLY']);

                getUserInfo().then((res) => {
                    if (res.code === "0000" && res.data.userExtInfo) {
                        let userExtInfo = res.data.userExtInfo;
                        let channelFullName = "";
                        let channelBelong = "";
                        if (userExtInfo.channelInfo) {
                            channelFullName = userExtInfo.channelInfo.channelFullName;
                            channelBelong = userExtInfo.channelInfo.channelBelong;
                        }
                        let channelObj = {
                            username: res.data.sysUser.username,
                            channelFullName: channelFullName,
                            deptIds: userExtInfo.deptIds,
                            deptId: userExtInfo.deptId,
                            channelBelong: channelBelong
                        }
                        if (userExtInfo.roles) {
                            let roles = userExtInfo.roles;
                            Array.isArray(roles) && roles.forEach(ele => {
                                let type = ele.roleTypeTemp;
                                if (roleCodeArr.has(ele.roleCode) && type && Array.isArray(type)) {
                                    type[0] ? role.add(type[0]) : '';
                                    type[1] ? role.add(type[1]) : '';
                                }
                                // if(roleCodeArr.has(ele.roleCode)) hasRoleCode = true;
                            });
                            let hasOldCar = role.has("oldCar");
                            let hasNewCar = role.has("newCar");
                            console.log(role, "hasNewCar")
                            !hasNewCar && hasOldCar ? this.businessTypeForm.businessType = '02' : '';
                            hasNewCar && !hasOldCar ? this.businessType = '01' : '';
                            !hasNewCar && hasOldCar ? this.businessType = '02' : '';
                            hasNewCar ? this.isNewCarDisabled = false : '';
                            hasOldCar ? this.isOldCarDisabled = false : '';
                            this.$emit("vehicleAuth", this.isNewCarDisabled, this.isOldCarDisabled, channelObj)
                            this.channelInfo = res.data.userExtInfo.channelInfo;
                            this.username = res.data.sysUser.username;
                            //channelBelong 00sp,01直营,02总对总
                            //businessType 01新车 02二手车
                            //choiceCardealerSwitch 0表示关，1表示开
                            if (this.channelInfo) {
                                if (this.channelInfo.channelBelong == "01") {
                                    this.isShowDealerId = true;
                                }
                            }
                            if (this.businessType == '01') {
                                this.dynamicDealerId();
                            }
                            console.log(this.isShowDealerId, "this.isShowDealerId");
                            // // 有车商
                            // if(this.isShowDealerId){
                            //     this.dynamicLocation=this.location;
                            // // 无车商
                            // }else{
                            // 当新车/二手车权限都有的时候，不为编辑进入则默认新车
                            if (this.applyNo) {
                                this.queryOrderInfo().then(data => {
                                    console.log(data.businessType, "businessType-applyNo")
                                    this.queryAdderssList(data.businessType)
                                })
                            } else {
                                if (diffType) {
                                    if (diffType == 'preApprove') {
                                        this.businessTypeForm.businessType = prebusiType;
                                        this.businessType = prebusiType;
                                        if (this.businessType == "01") {
                                            this.isPreOld = true;
                                        } else if (this.businessType == "02") {
                                            this.isPreNew = true;
                                        }
                                    }
                                }
                                console.log(prebusiType, this.businessType, "businessType")
                                this.queryAdderssList(this.businessType);

                            }
                            // }
                        }
                    }
                })
            },
            loadAddress(item, callback) {
                item.loading = true;
                // 有车商调此接口
                // if(this.isShowDealerId){
                //     getLocation({upperCode:item.value}).then(res => {
                //         if(res.code === "0000"){
                //             res.data.forEach(function(item) {
                //                 if(item.isParent){
                //                     item.loading = false;
                //                     item.children = [];
                //                 }
                //             });
                //             item.children = res.data;
                //             item.loading = false;
                //             callback();
                //         }
                //     })
                //     //无车商调此接口
                // }else{
                let param = {
                    username: this.username,
                    upperCode: item.value,
                }
                if (this.businessType == '01') {
                    param.businessType = 'newCar'
                } else if (this.businessType == '02') {
                    param.businessType = 'oldCar'
                }
                noDealerGetAddressList(param).then(res => {
                    if (res.code === "0000") {
                        res.data.forEach(function (item) {
                            if (item.isParent) {
                                item.loading = false;
                                item.children = [];
                            }
                        });
                        item.children = res.data;
                        item.loading = false;
                        callback();
                    }
                })
                // }
            },
            // 挂靠方式为网约车挂靠,挂靠信息运营公司选择获取上牌地址
            queryRecordAddress(location) {
                console.log(location, "location")
                this.$set(this.optionForm, 'licenseLocation', location);
                if (this.optionForm.licenseLocation) {
                    this.$refs["optionForm"].validateField('licenseLocation')
                }
                this.isNetLocation = true;
            },
            valiateAffiliated() {
                let valiteResult = true;
                this.$refs.affiliatedForm.validate((valid) => {
                    if (valid) {
                        valiteResult = valid;
                    } else {
                        valiteResult = false;
                    }
                })
                return valiteResult;
            }
        }
    }
</script>
